<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        img{
            max-width: 100%;
        }
    </style>
</head>
<body>
    <img id="car" src="https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSW,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203" alt="">
    <select name="" id="color_input">
        <option value="white">白色</option>
        <option value="block">黑色</option>
        <option value="silver">银色</option>
        <option value="blue">蓝色</option>
        <option value="red">红色</option>

    </select>
    <script>
        //流程代码
        /* const images={
            "white":'https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSW,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203',
            "block":'https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PBSB,$WX00,$IBE00&view=FRONT34&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203',
            "blue":'https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSB,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203',
            "red":'https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPMR,$WX00,$IBE00&view=FRONT34&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203',
            "silver":'https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PMNG,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203'
        }
        const color_input=document.getElementById('color_input');
        const imgEle=document.getElementById("car");
        color_input.addEventListener('change',function(){
            console.log(this.value);
            const current_color=this.value;
            imgEle.src=images[current_color];
        }); */
        class TeslaBuy{
            constructor(){
                console.log('对象创建');
                this.car=null;
                this.color_input=null;
                this.init();
                this.images={
            "white":'https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSW,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203',
            "block":'https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PBSB,$WX00,$IBE00&view=FRONT34&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203',
            "blue":'https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSB,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203',
            "red":'https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPMR,$WX00,$IBE00&view=FRONT34&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203',
            "silver":'https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PMNG,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203'
            }
            }
            
            init() {
                this.color_input=document.getElementById('color_input');
                this.car=document.getElementById("car");
                this.bindColorChangeEvent();
            }
            //换车色事件添加
            bindColorChangeEvent(){
                this.color_input.addEventListener('change',this.changeCarcolor.bind(this))
            }
            //更换车色
            changeCarcolor(){
                //bind 可以手动指定一个函数this指向
                console.log(this,'++++++');
                // console.log(this.value);
                const current_color=this.color_input.value;
                this.car.src=this.images[current_color];
            }
        }
        new TeslaBuy();
    </script>
</body>
</html>